start;
fEPHM = fopen('2021-5-25-11-48-52.e16','rb');

eph = zeros(100*32,34);
RangeSet = cell(1000,1);
SatposSet = cell(1000,1);
kr = 1;
ke = 1;
ks = 1;

while 1
    tag = fread(fEPHM,1,'int32');
    if (isempty(tag))
        break;
    end
    switch tag
        case 106990501
            head = fread(fEPHM,3,'int32');
            rangek.week = head(1);
            rangek.second = head(2);
            rangek.data = readRange(fEPHM, head(3));
            RangeSet{kr} = rangek;
            kr = kr+1;
        case 106990502
            ws = fread(fEPHM,2,'int32');
            for ii = 1:32
                ephk(1:2) = ws;
                ephk(3:end) = readEphem(fEPHM);
                eph((ke-1)*32+ii,:) = ephk;
            end
            ke = ke+1;
        case 106990503
            head = fread(fEPHM,3,'int32');
            satposk.week = head(1);
            satposk.second = head(2);
            satposk.data = readSatpos(fEPHM, head(3));
            SatposSet{ks} = satposk;
            ks = ks+1;
    end
    
end

fclose(fEPHM);

eph = eph(1:ke-1,:);
% RangeSet = RangeSet{1:kr-1};
% SatposSet = SatposSet{1:ks-1};
